package dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import modele.Province;
import modele.Region;

import services.persistance.BaseDAO;

public class ProvinceDao {

	
	public static List getListeProvinces(long idAdmin)
	{
		List liste = new ArrayList<>();
//		liste.add(idAdmin);
//		liste.add("rCegion");
		return BaseDAO.getInstance().getListObject("queryListeNomProvinces",liste);

	}
	
	public static void ajouterProvince(Province province) {
		BaseDAO.getInstance().ajouter(province);
	}
	
	public static void supprimerProvince(Province province) {
		BaseDAO.getInstance().supprimer(province);
	}
	public static List getProvincesRegion(long idRegion)
	{
		List liste = new ArrayList<>();
		liste.add(idRegion);
		return BaseDAO.getInstance().getListObject("queryProvincesRegion",liste);

	}
	
	public static void modifierProvince(Province province) {
		BaseDAO.getInstance().modifier(province);
	}
	
	public static Province getProvince(long idProvince) {
		return (Province) BaseDAO.getInstance().getObject(Province.class, idProvince);
	}
	public static ArrayList<Province> rechercherProvincesParCriteresParAdmin(Province province)
	{
		Criteria criteria = BaseDAO.getInstance().getSession().createCriteria(Province.class);
		criteria.add(Restrictions.like("nom", "%"+ province.getNom() +"%"));
		criteria.add(Restrictions.like("description", "%"+ province.getDescription() +"%"));
//		criteria.add(Restrictions.eq("population", region.getPopulation()));
		criteria.createCriteria("administrateur").add(Restrictions.eq("identifiant", province.getAdministrateur().getIdentifiant()));
		
		return (ArrayList<Province>) BaseDAO.getInstance().getListObjectByCriteria(criteria);
	}

}
